/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package facades;

import entities.Candidate;
import entities.Company;
import entities.Notification;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Alvaro
 */
@Stateless
public class NotificationFacade extends AbstractFacade<Notification> {
    @PersistenceContext(unitName = "ProyectoPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public NotificationFacade() {
        super(Notification.class);
    }
    
    public boolean isRequestedVideo(Candidate candidate, Company company){
        boolean res = false;
        Query namedQuery=em.createNamedQuery("Notification.findVideoRequest");
        namedQuery.setParameter("idUserSender", company.getIdUser().getIdUser());
        namedQuery.setParameter("idUserReceiver", candidate.getUser().getIdUser());
        if(namedQuery.getResultList()!= null && !namedQuery.getResultList().isEmpty() ){
            res = true;
        }
        return res;
    }
    public List<Notification> findNotificationsType(Integer type){
        List<Notification>res= new ArrayList<Notification>();
        Query namedQuery=em.createNamedQuery("Notification.findNotificationType");
        namedQuery.setParameter("notificationType", type);
        if(namedQuery.getResultList()!= null && !namedQuery.getResultList().isEmpty() ){
            res = namedQuery.getResultList();
        }
        return res;
    }
    
}
